package com.fuful;

import com.fuful.domain.Product;
import com.fuful.domain.Student;
import com.fuful.domain.Users;
import com.fuful.service.UsersService;
import org.springframework.context.ApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;

import javax.sql.DataSource;
import java.sql.Connection;

/**
 * Hello world!
 *
 */
public class App 
{
    public static void main( String[] args ) throws Exception
    {
        ApplicationContext applicationContext = new ClassPathXmlApplicationContext("application-context.xml");
        Users myUser = (Users)applicationContext.getBean("myUser2");
        System.out.println(myUser.getUname());
        System.out.println(myUser.getUpwd());
        Product myProduct = (Product)applicationContext.getBean("myProduct");
        System.out.println(myProduct.getPname());
        System.out.println(myProduct.getPtid().getPtname());
        Student myStu = (Student)applicationContext.getBean("myStu");
        System.out.println(myStu.getStuname()+myStu.getGradeClass().getGcname()+myStu.getGradeClass().getGrade().getGname());
//        DataSource dataSource = (DataSource)applicationContext.getBean("dataSource");
//        Connection connection = dataSource.getConnection();
//        if(connection != null){
//            System.out.println("OK");
//        }
        UsersService usersService = (UsersService) applicationContext.getBean("usersService");
        Users users = usersService.isLogin("my","q123456");
        System.out.println(users.getUpwd());
        System.out.println(usersService.updateUsersPassWord("my","qaz123"));
    }
}
